﻿using Lucene.Net.Support.IO;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Threading;

namespace Lucene.Net.Store.Azure
{
    /// <summary>
    /// Implements IndexInput semantics for a read only blob
    /// </summary>
    public class AzureIndexInput : IndexInput
    {
        public CloudBlob Blob { get; private set; }
        public MemoryStream _memoryStream;
        public AzureIndexInput(CloudBlob blob,Directory cacheDirectory, string resourceDesc) : base(resourceDesc)
        {
            Blob = blob;
            Blob.DownloadToStreamAsync(_memoryStream).Wait();
            if (!cacheDirectory.FileExists(resourceDesc))
            {
                cacheDirectory.
            }
        }

        public override long Length => _memoryStream.Length;

        public override long GetFilePointer()
        {
            throw new NotImplementedException();
        }

        public override byte ReadByte()
        {
            return (byte)_memoryStream.ReadByte();
        }

        public override void ReadBytes(byte[] b, int offset, int len)
        {
            _memoryStream.Read(b, offset, len);
        }

        public override void Seek(long pos)
        {
            _memoryStream.Seek(pos, SeekOrigin.Begin);
        }

        protected override void Dispose(bool disposing)
        {
            _memoryStream.Dispose();
        }
    }
}
